package com.yhy.tradesystem;

import java.util.Date;

import com.yhy.tradesystem.buysellsignal.SimpleCrossBuySellSignal;
import com.yhy.tradesystem.datasource.BaseDataSource.DataPeriod;
import com.yhy.tradesystem.datasource.SimpleYahooFileDataSource;
import com.yhy.tradesystem.datasource.YahooFileDataSource;
import com.yhy.tradesystem.techdata.BestMAFilter;
import com.yhy.tradesystem.techdata.MAFilter;
import com.yhy.tradesystem.techdata.TechDataBestParameterFinder;
import com.yhy.tradesystem.util.Log;

public class main {

	private static final String ROOTDIAR = "/home/hyyang/my-workspace/Stockchart/stockdata";
	private static final String STOCK = "SSE_index_Daily";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
//		testFindBest();
		testSoureFilterSignal();
	}
	
	private static void testFindBest() {
		SimpleYahooFileDataSource source = new SimpleYahooFileDataSource();
		source.setRootDir(ROOTDIAR);
		TechDataBestParameterFinder finder = new TechDataBestParameterFinder(MAFilter.class.getName(), null, null, MAFilter.PARAMETER_MA_DAY,MAFilter.DATA_MA+"/"+MAFilter.DATA_MA,
				SimpleCrossBuySellSignal.class.getName(), new String[]{SimpleCrossBuySellSignal.PARAMETER_FAST_LINE,SimpleCrossBuySellSignal.PARAMETER_SLOW_LINE},new String[]{Const.CLOSE,MAFilter.DATA_MA+"/"+MAFilter.DATA_MA},
				240);
		
		
		EmptyFilter debug = new EmptyFilter();
		
		
		source.connectOutput(finder);
		Log.d("main","test begin");
		
		Log.TAG_FILTER = finder.getName();

		float value = 30.0f;
		float window =5.0f;
		source.loadData(STOCK, DataPeriod.day);
		Log.startRecordLogFile("/home/hyyang/temp/stock/log");
		Log.consoleOuput = false;
		for(int i=0;i<365*18;i++){
			source.goNextTick();
			float start = value - window < 5.0f?5.0f:value -window;
			float ret[] = finder.getCurrentBestParameters(start, value+window, 1.0f);
//			float ret = finder.getCurrentBestParameters(5.0f, 50.0f, 1.0f);
			if(ret[0] > 0.0f){
				value = ret[0];
			}
		}
		
		Log.consoleOuput = true;
		Log.TAG_FILTER = null;
		Log.d("main","test finished");
	}

	private static void testSoureFilterSignal() {
		SimpleYahooFileDataSource source = new SimpleYahooFileDataSource();
		source.setRootDir(ROOTDIAR);
		
		MAFilter ma = new MAFilter();
		ma.setParameters(MAFilter.PARAMETER_MA_DAY, 30);
		
		BestMAFilter ma2 = new BestMAFilter();
		ma2.setParameters(BestMAFilter.PARAMETER_WINDOW_DAY, 240);
		
		EmptyFilter debug = new EmptyFilter();
		
		SimpleCrossBuySellSignal signal = new SimpleCrossBuySellSignal();
		signal.setStringParameters(SimpleCrossBuySellSignal.PARAMETER_FAST_LINE, Const.CLOSE);
		
		
		
		PositionMoneyController controller = new PositionMoneyController();
		source.loadData(STOCK, DataPeriod.day);
//		for(int i=0;i<365*5;i++){
//			source.goNextTick();
//		}
		
		signal.setStringParameters(SimpleCrossBuySellSignal.PARAMETER_SLOW_LINE, ma.getName()+"/"+MAFilter.DATA_MA);
		source.connectOutput(ma);
//		ma.connectOutput(debug);
		ma.connectOutput(signal);
		signal.connectOutput(controller);
		

//		signal.setStringParameters(SimpleCrossBuySellSignal.PARAMETER_SLOW_LINE, ma2.getName()+"/"+BestMAFilter.DATA_BESTMA_VALUE);
//		source.connectOutput(ma2);
//		ma2.connectOutput(signal);
//		signal.connectOutput(controller);
		
		
		Log.TAG_FILTER = "技术指标最优测试";;
		for(int i=0;i<7000;i++){
			source.goNextTick();
		}
		Log.TAG_FILTER = null;
		
		
		Log.d("main", controller.dumpMoneyChangeHistory());
		Log.d("main","test finished");
	}

}

